package org.example.net;

import lombok.SneakyThrows;

import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * @Auther:Liu
 * @Testname:DemoB1
 * @Date:2025/8/27 17:25
 */
public class DemoB1 {
    @SneakyThrows
    public static void main(String[] args) {
        System.out.println("开启通讯");
        //服务端 指定端口
        ServerSocket serverSocket = new ServerSocket(8889);
        System.out.println("开启了服务"+serverSocket);
        //开启一个通讯
        Socket socket = serverSocket.accept();
        //发送内容
        OutputStream outputStream = socket.getOutputStream();
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("Input:");
            String message = scanner.nextLine();
            outputStream.write(message.getBytes(StandardCharsets.UTF_8));
            if ("bye".equals(message)) {
                break;
            }
        }

    }
}
